package com.me.forum.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.me.forum.dao.IPlateDao;
import com.me.forum.domain.Category;
import com.me.forum.domain.Plate;
import com.me.forum.request.PageTypeRequest;
import com.me.forum.request.PlateRequest;
import com.me.forum.service.IPlateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;


@Service
public class PlateService extends BaseService<IPlateDao, Plate> implements IPlateService {
	@Autowired
	private CategoryService categoryService;
	/**
	 * @Description:分区获取所有板块
	 * @Author: Hao
	 * @Date: 2020/5/6 20:03
	 */
	@Override
	public IPage<Plate> getAll(PlateRequest preq, String page, String size) {
		Long categoryId = preq.getCategoryId() == null ? null : Long.valueOf(preq.getCategoryId());
		
		return getAll(
			Plate.builder()
				.categoryId(categoryId)
				.build(),
			page, size
		);
	}

	public boolean addPlate(PlateRequest preq) {
		if (!preq.isLegal()) {
			return false;
		}
		boolean save = dao.insertSelective(preq);

		return save ;
	}

	public boolean updateByPlate(PlateRequest preq) {
		if (!preq.isLegal()) {
			return false;
		}
		return dao.updateByPlate(preq) ;
	}

}